#import "BWThreadArrayController.h"
#import "BWThread.h"

@implementation BWThreadArrayController


- (NSArray *) keyPathsToSearch
{
    NSArray *paths;
    paths = [NSArray arrayWithObjects: @"name", @"manufacturerID", nil];

    return (paths);

} // keyPathsToSearch



// --------------------------------------------------
// Drag and Drop support

- (NSArray *) draggedTypes
{
    NSArray *draggedTypes;
    draggedTypes = [NSArray arrayWithObject: BWThread_CopiedRowsType];

    return (draggedTypes);

} // draggedTypes


- (BOOL) tableView: (NSTableView *) view
         writeRows: (NSArray *) rows    // array of indexes
      toPasteboard: (NSPasteboard *) pboard
{
    [pboard declareTypes: [self draggedTypes]
            owner: self];

    NSMutableArray *thingies;
    thingies = [NSMutableArray arrayWithCapacity: [rows count]];

    NSEnumerator *enumerator = [rows objectEnumerator];
    NSNumber *index;
    while (index = [enumerator nextObject]) {
        id thing;
        thing = [[self arrangedObjects]  objectAtIndex: [index intValue]];

        [thingies addObject: thing];
    }

    NSData *data;
    data = [NSArchiver archivedDataWithRootObject: thingies];

    BOOL doneWrote;
    doneWrote = [pboard setData: data
                        forType: BWThread_CopiedRowsType];

    return (YES);

} // writeRowsToPasteboard


@end // BWThreadArrayController

